const mongoose = require('../common/db');

const commentSchema = new mongoose.Schema({
    movie_id: { type: String, required: true },
    username: { type: String, required: true },
    content: { type: String, required: true, maxlength: 255 },
    checked: { type: Boolean, default: false },
    create_time: { type: Date, default: Date.now }
});

commentSchema.statics.query = async function (condition) {
    return await this.find(condition).exec();
}
commentSchema.statics.findByMovieId = async function (movie_id) {
    return await this.find({ movie_id }).exec();
};

commentSchema.statics.findByUsername = async function (username) {
    return await this.find({ username }).exec();
};

commentSchema.statics.findAll = async function () {
    return await this.find({}).exec();
};

module.exports = mongoose.model('Comment', commentSchema);